LIBNAME IN 'C:\Users\Scote\Dropbox\Income and inequality materials\Experiment';
DATA TEMP; SET IN.SASINEQUALITYEXPERIMENT;

/*relabel same variables so that statistical output is easier to read*/
LABEL SUBJEQULTY=' ';
LABEL RELIGIOSIT=' ';
LABEL LIBCON=' ';

/*recode the two experimental conditions*/
IF EQWEALTH=1 THEN DO;
EQUALITYCOND=1;
INEQUALITYCOND=0;
END;

IF UNEQWEALTH=1 THEN DO;
EQUALITYCOND=0;
INEQUALITYCOND=1;
END;

/*get frequencies for the two experimental conditions (inequality portrayed as higher vs. lower)*/
/*PROC FREQ;
TABLES EQUALITYCOND INEQUALITYCOND EQWEALTH UNEQWEALTH;
RUN;*/

/****recode the criterion variable and get frequencies and descriptives****/
IF GIVE0FRST NE . THEN TICKETSGIVEN=GIVE0FRST;
IF GIVE10FRST NE . THEN TICKETSGIVEN=GIVE10FRST;
/*PROC FREQ;
TABLES TICKETSGIVEN;
RUN;
PROC MEANS;
VAR TICKETSGIVEN;
RUN;*/

/*recode education*/
/*PROC FREQ;
TABLES EDUPARTICI;
RUN;*/
IF EDUPARTICI=1 THEN EDUCATION=1;
IF EDUPARTICI=2 THEN EDUCATION=2;
IF EDUPARTICI=3 THEN EDUCATION=3;
IF EDUPARTICI=4 THEN EDUCATION=4;
IF EDUPARTICI=5 THEN EDUCATION=5;
IF EDUPARTICI=6 THEN EDUCATION=6;
IF EDUPARTICI=7 THEN EDUCATION=6;
IF EDUPARTICI=-99 THEN EDUCATION=.;
/*PROC FREQ;
TABLES EDUPARTICI EDUCATION;
RUN;*/
/*recode education for those who picked "other" and then wrote something that fits one of the categories*/
IF ID=179 THEN EDUCATION=3; /*education label provided='Some College'*/
IF ID=205 THEN EDUCATION=3; /*education label provided='some college, no degree'*/
IF ID=242 THEN EDUCATION=3; /*education label provided='HS Diploma & CMA & One Year of Associate Accounting Degree'*/
IF ID=329 THEN EDUCATION=3; /*education label provided='CPhT'*/
IF ID=424 THEN EDUCATION=3; /*education label provided='some college'*/
IF ID=599 THEN EDUCATION=4; /*education label provided='nursing'*/
IF ID=627 THEN EDUCATION=3; /*education label provided='some college no degree'*/
IF ID=653 THEN EDUCATION=3; /*education label provided='Currently in College working towards Bachelor's'*/
IF ID=704 THEN EDUCATION=3; /*education label provided='some college, no degree'*/
IF ID=914 THEN EDUCATION=3; /*education label provided='2 yr college'*/
IF ID=1078 THEN EDUCATION=3; /*education label provided='Currently Pursuing Bachelor's Degree'*/
IF ID=1082 THEN EDUCATION=3; /*education label provided='Some College'*/
IF ID=1089 THEN EDUCATION=3; /*education label provided='a year and a half left to finish my bachlors'*/
IF ID=1092 THEN EDUCATION=3; /*education label provided='some college'*/
IF ID=1113 THEN EDUCATION=3; /*education label provided='some college, some vocational school, dV1 not graduate'*/
IF ID=1251 THEN EDUCATION=3; /*education label provided='Some JD work'*/
IF ID=1555 THEN EDUCATION=3; /*education label provided='some college'*/
IF ID=1588 THEN EDUCATION=3; /*education label provided='Current Undergraduate Student'*/
/*PROC FREQ;
TABLES EDUPARTICI EDUCATION;
RUN;
PROC MEANS;
VAR EDUCATION;
RUN;*/

/****recode demographic controls****/

/*recode age*/
AGEYRS=2013-(AGE+1910);
/*PROC MEANS;
VAR AGEYRS;
RUN;*/

/*recode ethnicity*/
/*PROC FREQ;
TABLES RACEPARTIC_1-RACEPARTIC_7;
RUN;*/
IF RACEPARTIC_1=1 THEN RACEAmericanIndian=1; ELSE RACEAmericanIndian=0;
IF RACEPARTIC_2=1 THEN RACEAsian=1; ELSE RACEAsian=0;
IF RACEPARTIC_3=1 THEN RACEAfricanAmerican=1; ELSE RACEAfricanAmerican=0;
IF RACEPARTIC_4=1 THEN RACEHispanic=1; ELSE RACEHispanic=0;
IF RACEPARTIC_5=1 THEN RACEPacificIslander=1; ELSE RACEPacificIslander=0;
IF RACEPARTIC_6=1 THEN RACEWhite=1; ELSE RACEWhite=0;
IF RACEPARTIC_7=1 THEN RACEOther=1; ELSE RACEOther=0;
/*PROC FREQ;
TABLES RACEPARTIC_1-RACEPARTIC_7 RACEAmericanIndian RACEAsian RACEAfricanAmerican RACEHispanic RACEPacificIslander RACEWhite RACEOther;
RUN;*/

/*recode employment status*/
IF Q78=1 THEN EMPLOYED=1; ELSE IF Q78=2 THEN EMPLOYED=1; ELSE IF Q78=3 THEN EMPLOYED=1; ELSE IF Q78=4 THEN EMPLOYED=0; ELSE IF Q78=5 THEN EMPLOYED=0; ELSE EMPLOYED=.;
/*PROC FREQ;
TABLES Q78 EMPLOYED;
RUN;*/

/*center individual-level predictor variables*/
/*PROC MEANS;
VAR AGEYRS RELIGIOSIT LIBCON EDUCATION HOUSEHOLDINCOME;
RUN;*/
CAGEYRS=AGEYRS-34.3214794;
CRELIGIOSIT=RELIGIOSIT-3.1214286;
CLIBCON=LIBCON-3.3939233;
CEDUCATION=EDUCATION-3.4147727;

/*divide household income values by 10,000 to aid interpretation*/
CHOUSEHOLDINCOMETHOUS=(HOUSEHOLDINCOME-55163.01)/10000;
CHOUSEHOLDINCOMETHOUSUPMIDSES=CHOUSEHOLDINCOMETHOUS-6.9837;
CHOUSEHOLDINCOMETHOUSLOWERSES=CHOUSEHOLDINCOMETHOUS+4.0163;

/*the next line creates a centered household variable with the mean for all participants including those who passed 0 or 1 comprehension checks*/
CHOUSEHOLDINCOMETHOUSALL=(HOUSEHOLDINCOME-53688.32)/10000;

/*PROC MEANS;
VAR AGEYRS CAGEYRS RELIGIOSIT CRELIGIOSIT LIBCON CLIBCON EDUCATION CEDUCATION HOUSEHOLDINCOME CHOUSEHOLDINCOMETHOUS;
RUN;*/

/*to check that results are the same without the one participant from DC, add this next line of code*/
/*IF STATE=9 THEN DELETE;*/

/*to compare just the highest across the two experimental conditions, add this next line of code*/
/*IF HOUSEHOLDINCOME=>100000;*/

/*get frequencies for variables -- some of this is redundant with above and is meant to verify calculations*/
PROC FREQ;
TABLES STATE INEQUALITYCOND FEMALE RACEAmericanIndian RACEAsian RACEAfricanAmerican RACEHispanic RACEPacificIslander RACEWhite RACEOther;
RUN;

/*get means for variables*/
PROC MEANS;
VAR SUBJEQULTY HOUSEHOLDINCOME CHOUSEHOLDINCOMETHOUS TICKETSGIVEN FEMALE RACEWhite AGEYRS RELIGIOSIT LIBCON EDUCATION EMPLOYED;
RUN;

/*get correlations between variables*/
PROC CORR;
VAR SUBJEQULTY HOUSEHOLDINCOME CHOUSEHOLDINCOMETHOUS TICKETSGIVEN FEMALE RACEWhite AGEYRS RELIGIOSIT LIBCON EDUCATION EMPLOYED;
RUN;

/*get means for income in the two experimental conditions*/
PROC SORT; BY INEQUALITYCOND; RUN;
PROC MEANS; BY INEQUALITYCOND;
VAR HOUSEHOLDINCOME;
RUN;

/*compare manipulation checks and all other variables across the two experimental conditions*/
PROC TTEST;
CLASS INEQUALITYCOND;
VAR SUBJEQULTY HOUSEHOLDINCOME CHOUSEHOLDINCOMETHOUS TICKETSGIVEN AGEYRS FEMALE RACEWhite EDUCATION EMPLOYED RELIGIOSIT LIBCON;
RUN;

/*compare manipulation checks on income for the wealthiest participants (need to include additional filter above)*/
PROC TTEST;
CLASS INEQUALITYCOND;
VAR HOUSEHOLDINCOME;
RUN;

/*test of interaction between income and inequality condition (condition coded to provide test of association between income and generosity in equality condition)*/
PROC GLM;
MODEL TICKETSGIVEN=CHOUSEHOLDINCOMETHOUS INEQUALITYCOND CHOUSEHOLDINCOMETHOUS*INEQUALITYCOND;
RUN;

/*test of interaction between income and inequality condition with condition recoded in order to test association between income and generosity in inequality condition*/
PROC GLM;
MODEL TICKETSGIVEN=CHOUSEHOLDINCOMETHOUS EQUALITYCOND CHOUSEHOLDINCOMETHOUS*EQUALITYCOND;
RUN;

/*test of interaction with controls*/
PROC GLM;
MODEL TICKETSGIVEN=CHOUSEHOLDINCOMETHOUS INEQUALITYCOND CHOUSEHOLDINCOMETHOUS*INEQUALITYCOND CAGEYRS FEMALE RACEWHITE CEDUCATION EMPLOYED CRELIGIOSIT CLIBCON;
RUN;

/*test of effect of inequality manipulation on generosity for top 15% and bottom 15%*/

PROC GLM;
MODEL TICKETSGIVEN=CHOUSEHOLDINCOMETHOUSUPMIDSES INEQUALITYCOND CHOUSEHOLDINCOMETHOUSUPMIDSES*INEQUALITYCOND;
RUN;

PROC GLM;
MODEL TICKETSGIVEN=CHOUSEHOLDINCOMETHOUSLOWERSES INEQUALITYCOND CHOUSEHOLDINCOMETHOUSLOWERSES*INEQUALITYCOND;
RUN;

